﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Data;
using System.IO;
using System.Linq;

using Cinch;


namespace Anata.Client
{
    /// <summary>
    /// </summary>
    public class KaryawanThumbnailViewModel : ViewModelBase
    {
        #region Data

        //private ViewMode currentViewMode = ViewMode.AddMode;

        #region Data.Primitives
        private Int32 idKaryawan;
        private String nama;
        private String alamat;
        private String noTelepon;
        private String noKTP;
        private String jenisKelamin;
        private DateTime? tanggalLahir;
        private String status;
        private String agama;
        private String golDarah;
        private DateTime? tanggalMasuk;
        private DateTime? tanggalKeluar;
        private Int32? idCabang;

        private bool isBusy;
        #endregion

        //private IEnumerable<DataWrapperBase> cachedListOfDataWrappers;

        #region Data.Rules
        #endregion

        #region Data.VMs
        private KaryawanKehadiranThumbnailViewModel kehadiranTerakhir;

        private DispatcherNotifiedObservableCollection<KaryawanLayananThumbnailViewModel> karyawanLayanans;
        private ICollectionView karyawanLayanansCV;

        private DispatcherNotifiedObservableCollection<TransaksiLayananThumbnailViewModel> jadwalKaryawans;
        private ICollectionView jadwalKaryawansCV;
        #endregion

        #region Data.Services
        #endregion

        #endregion

        #region Constructor
        public KaryawanThumbnailViewModel()
        {
            #region Constructor.SetupServices
            #endregion

            #region Constructor.SetupCommands
            #endregion

            #region Constructor.SetupDataWrappers
            #endregion

            //fetch list of all DataWrappers, so they can be used again later without the
            //need for reflection
            //cachedListOfDataWrappers =
            //    DataWrapperHelper.GetWrapperProperties<KaryawanThumbnailViewModel>(this);

            #region Constructor.SetupValidationRules
            #endregion

            #region Constructor.SetupVMs
            KehadiranTerakhir = new KaryawanKehadiranThumbnailViewModel();

            KaryawanLayanans = new DispatcherNotifiedObservableCollection<KaryawanLayananThumbnailViewModel>();
            KaryawanLayanansCV = CollectionViewSource.GetDefaultView(karyawanLayanans);

            JadwalKaryawans = new DispatcherNotifiedObservableCollection<TransaksiLayananThumbnailViewModel>();
            JadwalKaryawansCV = CollectionViewSource.GetDefaultView(jadwalKaryawans);
            #endregion

        }
        #endregion

        #region Static
        #endregion

        #region Public Properties
        #region Public.Commands
        #endregion

        #region Public.ViewMode
        #endregion

        #region Public.Data
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs idKaryawanChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.IdKaryawan);
        public Int32 IdKaryawan
        {
            get { return idKaryawan; }
            set
            {
                idKaryawan = value;
                NotifyPropertyChanged(idKaryawanChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs namaChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.Nama);
        public String Nama
        {
            get { return nama; }
            set
            {
                nama = value;
                NotifyPropertyChanged(namaChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs alamatChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.Alamat);
        public String Alamat
        {
            get { return alamat; }
            set
            {
                alamat = value;
                NotifyPropertyChanged(alamatChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs noTeleponChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.NoTelepon);
        public String NoTelepon
        {
            get { return noTelepon; }
            set
            {
                noTelepon = value;
                NotifyPropertyChanged(noTeleponChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs noKTPChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.NoKTP);
        public String NoKTP
        {
            get { return noKTP; }
            set
            {
                noKTP = value;
                NotifyPropertyChanged(noKTPChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs jenisKelaminChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.JenisKelamin);
        public String JenisKelamin
        {
            get { return jenisKelamin; }
            set
            {
                jenisKelamin = value;
                NotifyPropertyChanged(jenisKelaminChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs tanggalLahirChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.TanggalLahir);
        public DateTime? TanggalLahir
        {
            get { return tanggalLahir; }
            set
            {
                tanggalLahir = value;
                NotifyPropertyChanged(tanggalLahirChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs statusChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.Status);
        public String Status
        {
            get { return status; }
            set
            {
                status = value;
                NotifyPropertyChanged(statusChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs agamaChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.Agama);
        public String Agama
        {
            get { return agama; }
            set
            {
                agama = value;
                NotifyPropertyChanged(agamaChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs golDarahChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.GolDarah);
        public String GolDarah
        {
            get { return golDarah; }
            set
            {
                golDarah = value;
                NotifyPropertyChanged(golDarahChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs tanggalMasukChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.TanggalMasuk);
        public DateTime? TanggalMasuk
        {
            get { return tanggalMasuk; }
            set
            {
                tanggalMasuk = value;
                NotifyPropertyChanged(tanggalMasukChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs tanggalKeluarChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.TanggalKeluar);
        public DateTime? TanggalKeluar
        {
            get { return tanggalKeluar; }
            set
            {
                tanggalKeluar = value;
                NotifyPropertyChanged(tanggalKeluarChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs idCabangChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.IdCabang);
        public Int32? IdCabang
        {
            get { return idCabang; }
            set
            {
                idCabang = value;
                NotifyPropertyChanged(idCabangChangeArgs);
            }
        }
        #endregion

        #region Public.Busy
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs isBusyChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.IsBusy);
        public bool IsBusy
        {
            get { return isBusy; }
            set
            {
                isBusy = value;
                NotifyPropertyChanged(isBusyChangeArgs);
            }
        }
        #endregion

        #region Public.Cached Collection
        #endregion

        #region Public.DataVM
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs kehadiranTerakhirChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.KehadiranTerakhir);
        public KaryawanKehadiranThumbnailViewModel KehadiranTerakhir
        {
            get { return kehadiranTerakhir; }
            set
            {
                kehadiranTerakhir = value;
                NotifyPropertyChanged(kehadiranTerakhirChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs karyawanLayanansChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.KaryawanLayanans);
        public DispatcherNotifiedObservableCollection<KaryawanLayananThumbnailViewModel> KaryawanLayanans
        {
            get { return karyawanLayanans; }
            set
            {
                karyawanLayanans = value;
                KaryawanLayanansCV = CollectionViewSource.GetDefaultView(karyawanLayanans);
                NotifyPropertyChanged(karyawanLayanansChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs karyawanLayanansCVChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.KaryawanLayanansCV);
        public ICollectionView KaryawanLayanansCV
        {
            get { return karyawanLayanansCV; }
            set
            {
                karyawanLayanansCV = value;
                NotifyPropertyChanged(karyawanLayanansCVChangeArgs);
            }
        }

        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs jadwalKaryawansChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.JadwalKaryawans);
        public DispatcherNotifiedObservableCollection<TransaksiLayananThumbnailViewModel> JadwalKaryawans
        {
            get { return jadwalKaryawans; }
            set
            {
                jadwalKaryawans = value;
                NotifyPropertyChanged(jadwalKaryawansChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs jadwalsCVChangeArgs =
            ObservableHelper.CreateArgs<KaryawanThumbnailViewModel>(x => x.JadwalKaryawansCV);
        public ICollectionView JadwalKaryawansCV
        {
            get { return jadwalKaryawansCV; }
            set
            {
                jadwalKaryawansCV = value;
                NotifyPropertyChanged(jadwalsCVChangeArgs);
            }
        }
        #endregion

        #region Public.SummaryData
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs statusKaryawanChangeArgs =
            ObservableHelper.CreateArgs<KaryawanViewModel>(x => x.StatusKaryawan);
        public int StatusKaryawan
        {
            get
            {
                int retval = 0;
                if (tanggalKeluar.HasValue)
                {
                    retval = 99;
                }
                else if (kehadiranTerakhir != null && kehadiranTerakhir.WaktuMasuk.HasValue)
                {
                    retval = 0;
                }
                else
                {
                    retval = 1;
                }
                return retval;
            }
        }
        #endregion

        #endregion

        #region Command Handlers
        #endregion

        #region Mediator Message Sinks
        #endregion

        #region Private Methods
        #endregion

        #region Overrides
        public override string ToString()
        {
            return String.Format("KaryawanThumbnailViewModel {0}", this.idKaryawan);
        }
        #endregion

        #region EditableValidatingViewModelBase overrides
        #endregion
    }
}
